package com.le.tester.leetcode;

import org.apache.lucene.analysis.compound.hyphenation.CharVector;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * createTime：2022/11/22 15:29
 * description：找出字符串中第二大得数字
 */
public class SecondHighest {
    public int getSecondHighest(String s) {
        String numStr = s.replaceAll("[^0-9]", "");
        List<Integer> resultList = new ArrayList<>();

        int length = numStr.length();
        for (int i = 0; i < length; i++) {
            char c = numStr.charAt(i);
            int numericValue = Character.getNumericValue(c);
            resultList.add(numericValue);
        }
        List<Integer> collect = resultList.stream().sorted().distinct().collect(Collectors.toList());
        if (collect.size() < 2) {
            return -1;
        }

        return collect.get(collect.size() - 2);

    }

    public static void main(String[] args) {
        String s = "ck077";
        System.out.println(new SecondHighest().getSecondHighest(s));
    }
}
